package com.kede.typehanlder;

import com.kede.ienum.PayTypeEnum;
import com.kede.ienum.SourceChannelEnum;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/***
 ** @Author:Pr.li
 ** @Description:
 ** @Date: create in 2023/5/15 22:55
 ***/
public class SourceChannelEnumTypeHanlder extends BaseTypeHandler<SourceChannelEnum> {
    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, SourceChannelEnum parameter, JdbcType jdbcType) throws SQLException {
        ps.setInt(i,parameter.getEnumIndex());
    }

    @Override
    public SourceChannelEnum getNullableResult(ResultSet rs, String columnName) throws SQLException {
        int code = rs.getInt(columnName);
        SourceChannelEnum instance = SourceChannelEnum.parse(code);
        return instance;
    }

    @Override
    public SourceChannelEnum getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        int code = rs.getInt(columnIndex);
        SourceChannelEnum instance = SourceChannelEnum.parse(code);
        return instance;
    }

    @Override
    public SourceChannelEnum getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        return null;
    }
}
